package app.common;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;

/**
 * TODO
 *
 * @author zhaols
 * @date 2021-08-12 21:51
 */
@Data
public class Result {
     // 0 -success  1-error
    private int code;
    private String  message;
    private Object  data;

    public Result(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static String ok (String message, Object data){
        return JSON.toJSONString(new Result(0, message, data));
    }
    public static String ok (String message){
        return JSON.toJSONString(new Result(0, message, null));
    }
    public static String ok (Object data){
        return JSON.toJSONString(new Result(0, "Operation Succeeded", data));
    }
    public static String ok (){
        return JSON.toJSONString(new Result(0, "Operation Succeeded", null));
    }

    public static String error (String message){
        return JSON.toJSONString(new Result(1, message, null));
    }
    public static String error (){
        return JSON.toJSONString(new Result(1, "Operation Failed", null));
    }

}
